package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;
//5.3.0 根据楼层id查询房间
    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    //5.3.1新增床位
    @ApiOperation("新增床位")
    @PostMapping("/create")
    public ResponseResult addBed(@RequestBody BedDto bedDto) {
        bedService.addBed(bedDto);
        return success();
    }

    // 5.3.2 根据床位id 查询床位
    @ApiOperation("根据床位id查询床位")
    @GetMapping("/read/{id}")
    public ResponseResult queryBedById(@ApiParam("床位id") @PathVariable("id") Long id){
        return toAjax(bedService.queryBedById(id));
    }


    // 5.3.3 修改床位
    @ApiOperation("更新床位信息")
    @PutMapping("/update")
    public ResponseResult updateBed(@ApiParam("要更新的床位") @RequestBody BedDto bedDto){
        return  toAjax(bedService.updateBed(bedDto));
    }


    //5.3.4 根据id 删除床位
    @ApiOperation("根据床位id删除床位")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteBed(@ApiParam("床位id") @PathVariable("id") Long id) {
        return  toAjax(bedService.deleteById(id));
    }





}
